package com.daidai.component.configserver;

import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.api.exception.NacosException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Dax
 * @since 18:31  2019-06-12
 */
@RestController
@RequestMapping("/")
public class Api {
    @Value("${spring.application.name}")
    private  String name;
    @NacosValue(value = "${app.domain:default}",autoRefreshed = true)
    private String key;
    @GetMapping("/nacos")
    public String test(){
        return key;
    }
    @GetMapping("/name")
    public String name(){
        config();
        return name;
    }


    private void config(){


        try {
            ConfigService configService = NacosFactory.createConfigService("127.0.0.1:8848");
            String default_group = configService.getConfig("NACOS-CLIENT", "DEFAULT_GROUP", 5000);

            Resource resource=new ByteArrayResource(default_group.getBytes());


        } catch (NacosException e) {
            e.printStackTrace();
        }
    }
}
